#include <iostream>

int sum_arr(int arr[],int n);
int sum_arr2(const int* begin,const int* end);
int main(){
    using namespace std;
    int a[3] = {1,2,3};
    cout<<a<<endl;
    int res = sum_arr(a,3);     // 参数传递的是一个指针
    int res2 = sum_arr(a+1,2);   // 计算后两个元素的和
    int res3 = sum_arr2(a,a+3);
    cout<<res3;

    //const int d = 3;
    //int* pp = &d;          // 错误，不能将一个const修饰的数据类型的变量地址赋值给一个非静态类型的指针

    return 0;
}

int sum_arr(int arr[],int n){
    using std::cout;
    using std::endl;

    cout<<arr<<endl;
    int total = 0;
    for(int i=0;i<n;i++){
        total += arr[i]; 
    }

    return total;
}

int sum_arr2(const int* begin,const int* end){
    int total = 0;
    const int* p;
    for(p = begin;p != end;){
        total+=*p;
        p++;
    }

    return total;
}